package com.zcily.demo.controller;

import com.zcily.demo.entity.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/redis")
@Api(tags = "Redis测试")
public class RedisController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/get/{key}")
    @ApiOperation(value = "获取key的值")
    public Result<Object> get(@PathVariable("key") String key) {
        Object value = redisTemplate.opsForValue().get(key);
        return Result.ok(value);
    }

    @GetMapping("/set")
    @ApiOperation(value = "设置key的值")
    public Result<Object> set(@RequestParam("key") String key, @RequestParam("value") String value) {
        redisTemplate.opsForValue().set(key, value);
        return Result.ok();
    }
}